<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>
<head th:replace="common/head :: common_head(~{::title},~{})">
  <title>财税风险分析系统  |  企业所得税纳税申报表</title>
</head>

<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <div th:replace="common/header-user :: header"></div>
  
  <div th:replace="common/aside-user :: aside"></div>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
  
    <section class="content-header">
      <h1 id="page-title" active-aside="analysis-aside" active-menu="enterprise-income-tax-return-menu">企业所得税纳税申报表
        <small th:if="${reportGroup!=null&&#strings.equalsIgnoreCase(reportGroup.period,'ANNUAL')}">[[${#temporals.year(reportGroup.startDate)}]]年度</small>
        <small th:if="${reportGroup!=null&&#strings.equalsIgnoreCase(reportGroup.period,'SEMIANNUAL')}">[[${#temporals.month(reportGroup.startDate)&eq;1?'上':'下'}]半年度</small>
        <small th:if="${reportGroup!=null&&#strings.equalsIgnoreCase(reportGroup.period,'QUARTERLY')}">[[${#temporals.month(reportGroup.startDate)}]]季度</small>
        <small th:if="${reportGroup!=null&&#strings.equalsIgnoreCase(reportGroup.period,'MONTHLY')}">[[${#temporals.month(reportGroup.startDate)}]]月度</small>
      </h1>
      <ol class="breadcrumb">
        <li><a th:href="'/client/report/tax/index/'+${reportGroup.enterprise.id}"><i class="fa fa-list"></i> 企业所得税纳税申报表</a></li>
        <li class="active">列表</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content container-fluid">
      <div class="row" th:each="report : ${reportList}">
        <div class="col-sm-12">
          <h4>
            <a href="javascript:;" th:href="'/client/report/tax/reportSheet/'+${report.id}" th:text="${report.reportSpec.name}">利润表</a>
            <span><!-- （已完成） --></span>
            <small><a th:href="'/excel-template/'+${report.reportSpec.reportIndex}+'.xlsx'" style="margin-left: 30px;">下载模板</a></small>
            <small><a th:href="'javascript:openImportModal(\''+${report.id}+'\');'" style="margin-left: 30px;">导入模板</a></small>
          </h4>
        </div>
      </div>
      <!--  <div class="row">
        <div class="col-sm-12">
          <h4>
            <a href="/client/report/financial/balanceSheet">资产负债表</a>
            <a href="javascript:;" style="margin-left: 30px;">导入</a>
          </h4>
        </div>
      </div> -->
      <!--<div class="row">
        <div class="col-sm-12">
          <h4>
            <a href="javascript:;">现金流量表</a>
            <a href="javascript:;" style="margin-left: 30px;">导入</a>
          </h4>
        </div>
      </div> -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  
  <div class="modal modal-default fade" id="input-modal">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span></button>
          <h4 class="modal-title">导入模板</h4>
        </div>
        <div class="modal-body" style="height: 100px;">
          <form id="importForm">
            <input type="hidden" name="reportId">
            <div class="form-group">
              <label for="templateFile">选择文件</label>
              <input type="file" name="file" accept="application/vnd.ms-excel, application/vnd.ms-works, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
              <p class="help-block"></p>
            </div>
            <input type="reset" style="display:none;" />
          </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default pull-left" data-dismiss="modal">取消</button>
          <button type="button" class="btn btn-primary" onclick="importTemplate()">确认</button>
        </div>
      </div>
      <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
  </div>
  
  <div th:replace="common/footer :: footer"></div>

  <!-- Add the sidebar's background. This div must be placed
  immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<div th:replace="common/script :: script"></div>
<script>
  function openImportModal(reportId) {
    $('#input-modal input[name="reportId"]').val(reportId);
    $('#input-modal').modal('show');
  }
  
  function importTemplate() {
    var form = new FormData(document.getElementById("importForm"));
    $.ajax({
      url: "/import/report/" + $('#input-modal input[name="reportId"]').val(),
      data: form,
      processData: false,
      contentType: false,
      type: "PUT",
      success: function(data, textStatus) {
        console.log(data);
        alert('导入成功！');
        $("#input-modal input[type=reset]").trigger("click");
        $('#input-modal').modal('hide');
      },
      error: function (data, textStatus, errorThrown) {
        //console.log(textStatus);
        alert('导入失败！');
      },
      statusCode: {400: function() {
        alert('导入失败!未选择文件!');
      }}
    });
  }
</script>
</body>
</html>